package com.hospital.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;
import com.hospital.util.MD5;

@WebServlet("/manage/PersonInfoServlet")
public class PersonInfoServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			String account = request.getParameter("account").trim();
			String pswd = request.getParameter("pswd").trim();
			String md5password = MD5.MD5(pswd);
			String root = request.getParameter("root");
			String sex = request.getParameter("sex");
			String birthday = request.getParameter("birthday");
			String address = request.getParameter("address");
			String tel = request.getParameter("tel");
			String money = request.getParameter("money");
			String sql = "insert into t_user_info(account, md5password, root, sex, birthday, address, tel, money) values('"
			+ account + "', '" + pswd + "','" + root + "', '" + sex + "', '" + birthday + "', '" + address + "', '" + tel + "', '" + money + "')";
			DbUtil.add_modify(sql);
		} else if ("del".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_user_info", id);
		} else if ("modify".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String pswd = request.getParameter("pswd").trim();
			String md5password = MD5.MD5(pswd);
			String root = request.getParameter("root");
			String sex = request.getParameter("sex");
			String birthday = request.getParameter("birthday");
			String address = request.getParameter("address");
			String tel = request.getParameter("tel");
			String sql = "update t_user_info set pswd = '" + md5password + "', root = '" + root + "', sex = '" + sex + 
					"', birthday = '" + birthday + "', address = '" + address + "', tel = '" + tel + "' where id = " + id;
			DbUtil.add_modify(sql);
		}
		request.setAttribute("rs", "修改成功。");
		request.getRequestDispatcher("/manage/person_info.jsp").forward(request, response);
	}
}